package com.haizhi.crm.persist.manager.impl;

import com.haizhi.crm.common.constant.SearchStatus;
import com.haizhi.crm.common.exception.UnexpectedStatusException;
import com.haizhi.crm.common.rest.RestService;
import com.haizhi.crm.persist.manager.EsPersistManager;
import com.haizhi.crm.persist.model.PersistResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by chengmo on 2018/6/19.
 */
@Service
public class EsPersistManagerImpl implements EsPersistManager {

    private static final String PATH_BULK_PERSIST = "/bulkPersist";

    @Value("${search.manager.url.graph-dc-es:}" )
    private String restUrl;
    @Autowired
    private RestService restService;

    @Override
    public PersistResp bulkPersist(Map<String, Object> requestApi) {
        try {
            return restService.doPost(restUrl + PATH_BULK_PERSIST, requestApi, PersistResp.class);
        } catch (Exception e) {
            throw new UnexpectedStatusException(SearchStatus.CALL_REST_ERROR, e, requestApi);
        }
    }
}
